package top.majuan.study.study.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "twoServlet", value = "/two.html")
public class TwoServlet extends HttpServlet {
//    响应get请求
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
//    响应post请求
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        设置应答的类型
        resp.setContentType("text/html");
//        设置应答的编码
        resp.setCharacterEncoding("UTF-8");
//        输出应答的内容
        PrintWriter out = resp.getWriter();
        out.println("<h1>黑暗骑士你好!</h1>");
        out.close();
    }
}
